import axios from 'axios'
import qs from 'qs'

export default {
	namespaced: true,
	actions: {
		addRemark: function ({commit}, params) {
			let {callback} = params;
			
			params.onget = function ({data}) {
				callback(data.success)
			}
			
			commit("addRemark", params)
		},
		getAllRemark: function ({commit}, params) {
			let {callback} = params;
			
			params.onget = function ({data}) {
				callback(data)
			}
			
			commit("getAll", params)
		},
		deleteRemark: function ({commit}, params) {
			let {callback} = params;
			
			params.onget = function ({data}) {
				callback(data.success)
			}
			
			commit("delRemark", params)
		},
	},
	mutations: {
		addRemark: function (state, {content, pageId, userId, onget}) {
			axios.post("/remark", {
				content, pageId, userId
			})
				.then((data) => {
					onget(data);
				});
		},
		getAll: function (state, {onget, content, pageId, userId, page=0, size=4}) {
			axios.get('/remark', {
				params: {
					content,
					pageId,
					userId,
					page,
					size
				}
			}).then(res => {
				onget(res);
			})
		},
		delRemark: function (state, {onget, id}) {
			axios.delete('/remark', {params: {id}}).then(data => {
				onget(data)
			})
		}
	}
}